package com.mmy.controller.restaurant;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.mmy.domain.restaurant.TRestaurantOrder;
import com.mmy.domain.restaurant.VRestaurantPlan;
import com.mmy.domain.sys.TSysUser;
import com.mmy.service.impl.restaurant.RestaurantOrderServiceImpl;
import com.mmy.service.impl.restaurant.RestaurantPlanServiceImpl;

/**
 * 类的介绍：餐馆订单
 *
 * @author shangzl
 * @date 创建日期：
 * @version 1.0
 */

@Controller
public class RestaurantOrderController {

	@Autowired
	RestaurantOrderServiceImpl restaurantOrderServiceImpl;

	@Autowired
	RestaurantPlanServiceImpl restaurantPlanServiceImpl;

	/**
	 * 函数功能说明： 前台个人中心点击取消餐馆预留
	 *
	 * @param 参数说明 tSysUser:用户类 用户 session
	 * @return 返回值说明 jsp页面
	 * @throws 异常处理说明
	 * @author 创建人 hanxl
	 * @date 创建日期 2020.10.29
	 */
	@RequestMapping(value = "/enterrestaurantcancelreserve")
	public String enterRestaurantCancelReserve(HttpServletRequest request, HttpSession session) {

		int iID = Integer.parseInt(request.getParameter("iID"));
		TSysUser sessionSysUser = (TSysUser) session.getAttribute("tSysUser");
		restaurantOrderServiceImpl.updateState(iID, sessionSysUser);
		return "redirect:myrestaurantreserve";

	}

	/**
	 * 函数功能说明： 前台个人中心点击申请餐馆退单
	 *
	 * @param 参数说明 tSysUser:用户类 用户 session
	 * @return 返回值说明 jsp页面
	 * @throws 异常处理说明
	 * @author 创建人 hanxl
	 * @date 创建日期 2020.10.29
	 */
	@RequestMapping(value = "/enterrestaurantapplyrefund")
	public String enterRestaurantApplyRefund(HttpServletRequest request, HttpSession session) {

		int iID = Integer.parseInt(request.getParameter("iID"));
		TSysUser sessionSysUser = (TSysUser) session.getAttribute("tSysUser");
		restaurantOrderServiceImpl.updateRefundState(iID, sessionSysUser);
		return "redirect:myrestaurantorder";
	}

	/**
	 * 函数功能说明： 前台个人中心点击撤销餐馆退单
	 *
	 * @param 参数说明 tSysUser:用户类 用户 session
	 * @return 返回值说明 jsp页面
	 * @throws 异常处理说明
	 * @author 创建人 hanxl
	 * @date 创建日期 2020.10.29
	 */
	@RequestMapping(value = "/enterrestaurantcancelrefund")
	public String enterRestaurantCancelRefund(HttpServletRequest request, HttpSession session) {

		int iID = Integer.parseInt(request.getParameter("iID"));
		TSysUser sessionSysUser = (TSysUser) session.getAttribute("tSysUser");
		restaurantOrderServiceImpl.updateCancelState(iID, sessionSysUser);
		return "redirect:myrestaurantrefund";
	}

	/* 前台个人中心显示订单详情 */
	@RequestMapping(value = "/myrestaurantinfo")
	public String toMyRestaurantInfo(HttpServletRequest request, Model model) {

		int iID = Integer.parseInt(request.getParameter("iID"));

		TRestaurantOrder dbRestaurantOrder = restaurantOrderServiceImpl.findByID(iID);
		model.addAttribute("dbRestaurantOrder", dbRestaurantOrder);

		String strOrderID = dbRestaurantOrder.getOrderID();
		int iPlanID = Integer.parseInt(strOrderID.substring(9, 18));

		VRestaurantPlan dbRestaurantPlan = restaurantPlanServiceImpl.findByPlanID(iPlanID);

		model.addAttribute("dbRestaurantPlan", dbRestaurantPlan);

		return "permanagement/MyRestaurantInfo";
	}
}
